package com.lancoo.edu.platform.operation.backupRestore.constant;

import com.lancoo.edu.platform.operation.backupRestore.service.timer.job.BackUpDatabaseJob;
import com.lancoo.edu.platform.operation.backupRestore.service.timer.job.DeleteBackupJob;
import com.lancoo.edu.platform.operation.backupRestore.service.timer.job.UpdateServerSysIpJob;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.quartz.Job;

/**
 * @author lzh
 * @date 2024/6/20 17:08
 * @description 定时任务枚举
 */
@AllArgsConstructor
@Getter
public enum ScheduleTaskEnum {


    /**
     * 备份任务
     */
    BACKUP_TASK("backUpDatabaseJob", "15", "备份数据库任务", BackUpDatabaseJob.class),

    /**
     * 删除备份文件任务
     */

    DELETE_BACKUP_FILE_TASK("deleteBackupJob", "0 0 1 * * ? ", "删除备份文件任务", DeleteBackupJob.class),

    /**
     * 更新系统数据库IP地址任务
     */

    UPDATE_SYSTEM_DATABASE_IP_ADDRESS_TASK("updateServerSysIpJob", "0 0 0/1 * * ? ", "更新系统对应服务器IP任务", UpdateServerSysIpJob.class);

    /**
     * 任务方法名
     */
    private final String taskMethod;

    /**
     * 默认任务表达式
     */
    private final String cronExpression;

    /**
     * 任务描述
     */
    private final String description;

    /**
     * 对应任务类
     */
    private final Class<? extends Job> clazz;


    /**
     * 根据任务方法名称获取枚举对象
     *
     * @param taskMethod 任务方法名
     * @return 枚举对象
     */
    public static ScheduleTaskEnum getEnumByTaskMethod(String taskMethod) {
        for (ScheduleTaskEnum scheduleTaskEnum : ScheduleTaskEnum.values()) {
            if (scheduleTaskEnum.getTaskMethod().equals(taskMethod)) {
                return scheduleTaskEnum;
            }
        }
        return BACKUP_TASK;
    }

}
